import {request} from "../utils/request";
import {SongItem, HotKeyVo, AlbumSort, AlbumBrief} from "./types";

function hotKeys(): Promise<HotKeyVo[]> {
  // return FetchData
  return request.fetch({url: '/search/hot'}).then(res => res.data) as unknown as Promise<HotKeyVo[]>;
}

function searchSong(key: string): Promise<SongItem[]> {
  return request.fetch({url: '/search/quick', params: { key }}).then((res: any) => res.data.song.itemlist) as unknown as Promise<SongItem[]>;
}

function albumSorts(): AlbumSort[] {
  return [
    {
      id: 6,
      name: '流行'
    },
    {
      id: 136,
      name: '经典'
    },
    {
      id: 116,
      name: '治愈'
    }
  ];
}


function getAlbums(category: number): Promise<AlbumBrief[]> {
  return request.fetch({url: '/songlist/list', params: { category }}).then((res: any) => res.data.list) as unknown as Promise<AlbumBrief[]>;
}

export { hotKeys, searchSong, albumSorts, getAlbums };
